package com.bw.module_house.view

import androidx.activity.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.lib_base.path.RouterPath
import com.bw.lib_base.view.BaseActivity
import com.bw.module_house.R
import com.bw.module_house.adapter.TabAdapter
import com.bw.module_house.databinding.ActivityRentingHouseBinding
import com.bw.module_house.viewmodel.HouseViewModel
/**
 * 智慧园区-03-房源信息V1.1-史建军-20250515
 */
@Route(path = RouterPath.PATH_RENTING_HOUSE_ACTIVITY)
class RentingHouseActivity : BaseActivity<ActivityRentingHouseBinding>() {

    private val vm by viewModels<HouseViewModel> { ViewModelProvider.NewInstanceFactory()  }
    private val tabAdapter:TabAdapter  by lazy { TabAdapter() }


    override fun initView() {
        vm.getHouseList()
        vm.houseSuccess.observe(this){
            tabAdapter.data.clear()
            tabAdapter.data.addAll(it)
            tabAdapter.notifyDataSetChanged()
        }
        mDataBinding.topLayout.iconBack.setOnClickListener {
            finish()
        }
        mDataBinding.topLayout.tvName.text = "租户管理"
        mDataBinding.rvRenting.adapter = tabAdapter
        mDataBinding.rvRenting.layoutManager=LinearLayoutManager(this)
        mDataBinding.topLayout.iconSerch.setOnClickListener {
            val et1=mDataBinding.topLayout.etSearch.text.toString()
            vm.getHouseListSearch(et1)
            vm.houseSuccess.observe(this){
                tabAdapter.data.clear()
                tabAdapter.data.addAll(it)
                tabAdapter.notifyDataSetChanged()
            }
        }


    }
    override fun getLayoutId(): Int =R.layout.activity_renting_house

}